package com.javawork.juc.one;

import java.util.concurrent.TimeUnit;

/**
 * @author zhangxiaolu
 * @date 2023-2-5 14:41
 */
public class DaemonDemo {

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "\t 开始运行，" + (Thread.currentThread().isDaemon() ? "守护线程" : "用户线程"));

        }, "t1");
        t1.setDaemon(true);// 必须设置在start之前
        t1.start();
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + "\t ----end 主线程");
    }
}
